# Copyright 2012 Brett Ponsler
# This file is part of siriviewer.
#
# siriviewer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# siriviewer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with siriviewer.  If not, see <http://www.gnu.org/licenses/>.
'''The siriButton module contains the SiriButtonWidget class which provides
a BaseWidget implementation for the Siri request button.

'''
from os.path import join

from PyQt4.Qt import SIGNAL
from PyQt4 import uic, QtGui, Qt, QtCore

from siriviewer.objectView import ObjectView

from pyamp.ui.qt import BaseWidget, StyleSheet, LayoutType


class SiriButtonWidget(BaseWidget):
    '''The SiriButtonWidget class creates a BaseWidget that is the Siri
    request button. It allows containing classes to trigger on the button
    click event, and creates a horizontal layout so that the Siri button
    is centered in the view.

    '''
    layoutType = LayoutType.Horizontal
    '''Use a horizontal layout so that the Siri button is centered in the view.

    '''

    # @todo: use config file to get this directory
    __ImageDir = join("/home", "bponsler", "personal", "projects", "python",
                      "siriviewer", "images")
    __ButtonImage = join(__ImageDir, "siri_button.png")

    __ClickedSignal = SIGNAL("clicked()")
    '''Define the signal emitted when the button is clicked, and re-emitted
    on the widget so containing widgets can catch the event.

    '''

    def createElements(self):
        '''Override the createElements method for BaseWidget.'''
        self.__button = self.__createSiriButton()

        # Add two horizontal spacers around the button
        return [self.__button]

    def __createSiriButton(self):
        '''Create the siri button widget.'''
        button = QtGui.QPushButton()
        button.setMinimumSize(56, 56)
        button.setMaximumSize(56, 56)

        # Add the Siri button to the button
        styleSheet = StyleSheet(border_image="url(%s)" % self.__ButtonImage)
        button.setStyleSheet(str(styleSheet))

        return button

    def setupConnections(self):
        '''Setup connections to the button click event.'''
        self.connect(self.__button, self.__ClickedSignal, self.__buttonClicked)

    def __buttonClicked(self):
        '''The button was clicked. Re-emit the signal on the widget so
        containing widgets can trigger on the button click event.

        '''
        self.emit(self.__ClickedSignal)
